using System;
using System.Collections;
using System.Collections.Generic;
using System.Web.UI;
namespace JQueryControlToolkit.Controls
{
	public class ContainerChildrenCollection<T> : IList<T>, ICollection<T>, IEnumerable<T>, IList, ICollection, IEnumerable where T : Control, JSObject
	{
		private Container<T> container;
		private ControlCollection innerList
		{
			get
			{
				return this.container.Controls;
			}
		}
		public int Count
		{
			get
			{
				return this.innerList.Count;
			}
		}
		public bool IsReadOnly
		{
			get
			{
				return this.innerList.IsReadOnly;
			}
		}
		public T this[int index]
		{
			get
			{
				return (T)((object)this.innerList[index]);
			}
			set
			{
				this.RemoveAt(index);
				this.Insert(index, value);
			}
		}
		bool IList.IsFixedSize
		{
			get
			{
				return false;
			}
		}
		object IList.this[int index]
		{
			get
			{
				return this[index];
			}
			set
			{
				this[index] = (T)((object)value);
			}
		}
		bool ICollection.IsSynchronized
		{
			get
			{
				throw new NotSupportedException();
			}
		}
		object ICollection.SyncRoot
		{
			get
			{
				throw new NotSupportedException();
			}
		}
		public ContainerChildrenCollection(Container<T> container)
		{
			this.container = container;
		}
		public void Add(T item)
		{
			this.innerList.Add(item);
		}
		public void Clear()
		{
			this.innerList.Clear();
		}
		public bool Contains(T item)
		{
			return this.innerList.Contains(item);
		}
		public void CopyTo(T[] array, int arrayIndex)
		{
			this.innerList.CopyTo(array, arrayIndex);
		}
		public bool Remove(T item)
		{
			this.innerList.Remove(item);
			return true;
		}
		public IEnumerator<T> GetEnumerator()
		{
			IEnumerator enumerator = this.innerList.GetEnumerator();
			try
			{
				while (enumerator.MoveNext())
				{
					T t = (T)((object)enumerator.Current);
					yield return t;
				}
			}
			finally
			{
				IDisposable disposable = enumerator as IDisposable;
				if (disposable != null)
				{
					disposable.Dispose();
				}
			}
			yield break;
		}
		IEnumerator IEnumerable.GetEnumerator()
		{
			return this.innerList.GetEnumerator();
		}
		public int IndexOf(T item)
		{
			return this.innerList.IndexOf(item);
		}
		public void Insert(int index, T item)
		{
			this.innerList.AddAt(index, item);
		}
		public void RemoveAt(int index)
		{
			this.innerList.RemoveAt(index);
		}
		int IList.Add(object value)
		{
			this.Add((T)((object)value));
			return 1;
		}
		bool IList.Contains(object value)
		{
			return this.Contains((T)((object)value));
		}
		int IList.IndexOf(object value)
		{
			return this.IndexOf((T)((object)value));
		}
		void IList.Insert(int index, object value)
		{
			this.Insert(index, (T)((object)value));
		}
		void IList.Remove(object value)
		{
			this.Remove((T)((object)value));
		}
		void ICollection.CopyTo(Array array, int index)
		{
			throw new NotSupportedException();
		}
		internal JSObject[] ToArray()
		{
			T[] array = new T[this.Count];
			for (int i = 0; i < this.Count; i++)
			{
				array[i] = this[i];
			}
			return (JSObject[])array;
		}
	}
}
